package shiyan6;

public class Student extends Person {
	 private String Zhuanye;
	    private String Minzu;
	    private Course[] courses;
	    public Student() {
	        courses = new Course[3];
	    }
	    public Student(int stuId,String stuName,String sex,String minzu,String zhuanye) {
	        this.Id = stuId;
	        this.Name = stuName;
	        this.sex = sex;
	        this.Minzu = minzu;
	        this.setZhuanye(zhuanye);
	        courses = new Course[3];
	    }

		public String getZhuanye() {
			return Zhuanye;
		}
		public void setZhuanye(String zhuanye) {
			Zhuanye = zhuanye;
		}
		public String getMinzu() {
			return Minzu;
		}
		public void setMinzu(String minzu) {
			Minzu = minzu;
		}
	    public boolean Selected(Course course){
	        boolean cnt=false;
	        for(Course c:courses){
	            if(c==course){
	                cnt=true;
	                break;
	            }
	        }
	        return cnt;
	    }
	    public boolean Null(Course course){
	        boolean cnt=false;
	        for(Course c:courses){
	            if(c==null){
	                cnt=true;
	                break;
	            }
	        } 
	        return cnt;
	    }
	    
	    public boolean addCourse(Course course){
	        boolean cnt=false;
	        if(!Selected(course)&&Null(course)){
	            for(int i=0;i<this.courses.length;i++){
	                if(courses[i]==null){
	                    courses[i]=course;
	                    course.addStudent(this);     
	                    cnt=true;
	                    break;
	                }
	            }
	        }
	        return cnt;
	    }
	    
	    public boolean removeCourse(Course course){
	        boolean cnt=false;
	        if(Selected(course)){
	            for(int i=0;i<this.courses.length;i++){
	                if(courses[i]==course){
	                    courses[i]=null;
	                    course.removeStudent(this); 
	                    cnt=true;
	                    break;
	                }
	            }
	        }
	        return cnt;
	    }
	    
	    public void displayCourse(){
	    	 System.out.println(this.Name+"  "+this.Id+"  "+this.sex+"  "+this.Minzu+"  "+this.Zhuanye);
	        for(Course c:courses){
	            if(c!=null){
	                System.out.print("课程编号："+c.getId()+"\n所选课程："+c.getName()+"\n上课地点："+c.getDestination()+"\n上课时间："+c.getTime()+"\n");
	            }
	        }
	        System.out.println();
	    }
	    
	    
	    public String toString(){
	    	String str0 = this.Name+"  "+this.Id+"  "+this.sex+"  "+this.Minzu+"  "+this.Zhuanye;
	    	String str1 = new String();
	    	for(Course c:courses){
	    		if(c!=null){
	    		str1 = "课程编号："+c.getId()+"\n所选课程："+c.getName()+"\n上课地点："+c.getDestination()+"\n上课时间："+c.getTime()+"\n";
	    		}
	    	}	
	    	String str =str0+str1;
	    	System.out.println(str);
			return str;
}
	    
	    public String toString(){
	    	StringBuffer str =new StringBuffer();	
	    	String str1 = "";
	    	String str0 = this.Name+"  "+this.Id+"  "+this.sex+"  "+this.Minzu+"  "+this.Zhuanye+"\n";
	    	for(Course c:courses){
	    		if(c!=null){
	    			
	    		str1 = "课程编号："+c.getId()+"\n所选课程："+c.getName()+"\n上课地点："+c.getDestination()+"\n上课时间："+c.getTime()+"\n";
	    		str = str.append(str1);
	    		}
	    	}	
	    	String str3 =str0 + str.toString() ;
	    	 return str3;
}
	  
}
